const { context } = require('esbuild')
const args = require('minimist')(process.argv.slice(2))
const { resolve } = require('path')

const target = args._[0]
const format = args.f || 'iife'

const pkg = require(resolve(__dirname, `../packages/${target}/package.json`))
const globalName = pkg.buildOptions.globalName
const buildFormat = format === 'global' ? 'iife' : format === 'cjs' ? 'cjs' : 'esm'
const entry = resolve(__dirname, `../packages/${target}/src/index.ts`)
const outfile = resolve(__dirname, `../packages/${target}/dist/${target}.${format}.js`)
context({
  entryPoints: [entry],
  outfile: outfile,
  sourcemap: true,
  bundle: true,
  globalName: globalName,
  format: buildFormat,
}).then(ctx => {
  console.log("watching~~");
  ctx.watch()
})



